home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / prgccpc.c < prev    next >
C/C++ Source or Header  |  1991-12-20  |  6KB  |  232 lines

  1. /* prgccpc.c */
  2. /* machine dependent code for delorie's GCC 
  3.    for PC 386's (a DOS extender)   
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include "prtypes.h"
  9.  
  10. #define CANTALLOCATE "cant allocate "
  11. #define CRPLEASE "Carriage return please"
  12. #define NOCONFIGFILE "sprolog.inf missing using default configuration"
  13. #define CONFIG_FILE "sprolog.inf"
  14. #define YESUPPER 'Y'
  15. #define YESLOWER 'y'
  16.  
  17. extern FILE *Log_file, *Curr_outfile;
  18. extern void exit_term();
  19.  
  20. /**************************** os_alloc() *********************************/
  21. /* This is the function you use to get memory  from the system.         */
  22. /* Why not use malloc? Because malloc will only allocate up to 64K  on   */
  23. /* some systems when there is another function around for larger      */
  24. /* allocations.                                 */
  25.     
  26. char *os_alloc(how_much)
  27. zone_size_t how_much;
  28. {
  29.     char *ret, *malloc();
  30. #ifdef DEBUG
  31. printf("trying to allocate %u\n",how_much);
  32. #endif
  33.     if((ret = malloc(how_much)) == NULL)
  34.     {
  35.         errmsg(CANTALLOCATE);
  36.         exit_term();
  37.         exit(1);
  38.         return(NULL);/* for stupid finicky compilers and lint */
  39.     }
  40.     else
  41. #ifdef DEBUG 
  42. printf("successful\n");
  43. #endif
  44.         return(ret);
  45. }
  46.  
  47. /******************************************************************************
  48.  Initialise terminal
  49.  This is the function you use to set up your terminal for interaction with
  50.  sprolog. It would change if you wanted to incorporate a line editor for example
  51.  ******************************************************************************/
  52. void ini_term()
  53. {
  54.  
  55. }
  56.  
  57. /******************************************************************************
  58.             function exit_term
  59.  This restores the terminal characteristics.
  60.  ******************************************************************************/
  61. void exit_term()
  62. {
  63.  
  64. }
  65.  
  66. /***************************** errmsg() *********************************
  67.  Output error message.
  68.  On some systems you might want to output a box-surrounded message.
  69.  ******************************************************************************/
  70.  
  71. errmsg(s)
  72. char *s;
  73. {
  74. #if LOGGING_CAPABILITY
  75.     if(Log_file){
  76.       fprintf(Log_file, "%s", s);
  77.         fflush(Log_file);
  78.         }
  79. #endif
  80.     fprintf(stdout, "%s\n", s);
  81. }
  82.  
  83. /************************** tty_getc() *********************************
  84.  Read a char from terminal, no matter what the other flags are.
  85.  ******************************************************************************/
  86.  
  87. int tty_getc()
  88. {
  89. int c;
  90.  
  91. c = getchar();
  92.  
  93. #ifdef LOGGING_CAPABILITY
  94. if(Log_file!=NULL)
  95.   {
  96.   fputc(c,Log_file);
  97.   }
  98. #endif
  99.  
  100. return(c);
  101. }
  102.  
  103. tty_getche()
  104. {
  105. int c;
  106. c = getkey();
  107. putchar(c);
  108. fflush(stdout);
  109. return c;
  110. }
  111.  
  112. /************************** tty_pr_string() *********************************
  113.  Output string to the terminal no matter what the other flags are.
  114.  ******************************************************************************/
  115.  
  116. int tty_pr_string(s)
  117. char *s;
  118. {
  119. int len;
  120. #ifdef LOGGING_CAPABILITY
  121. if(Log_file  != NULL)
  122.   {
  123.     fprintf(Log_file,"%s",s);
  124.     fflush(Log_file);
  125.   }
  126. #endif
  127.     len = printf("%s",s);
  128.     fflush(stdout);
  129. return (len);
  130. }
  131.  
  132. /*******************************************************************
  133.             pr_string()
  134.  This will output a string to the current output file.
  135.  It also returns the number of chars output.
  136.  It should be the only way your functions can output a string.
  137.  *******************************************************************/
  138.  
  139. int pr_string(s)
  140. char *s;
  141. {
  142. int len;
  143.  
  144. #if LOGGING_CAPABILITY
  145.     extern FILE *Log_file;
  146.     if (Log_file != NULL)
  147.     {
  148.     fprintf(Log_file, "%s", s);
  149.     fflush(Log_file);
  150.     }
  151. #endif
  152.     len = fprintf(Curr_outfile, "%s", s);
  153.     fflush(stdout);
  154. return(len);
  155. }
  156.  
  157. /**************************** read_config() **********************************
  158.  this reads the file SPROLOG.INF so that the sizes of the various 
  159.   memory zones can be set.
  160.  ************************************************************************/
  161.  
  162. int read_config(hsp, strsp, dsp, tsp, sbsp, tmpsp, rsp, psp)
  163. zone_size_t *hsp, *strsp, *dsp, *tsp, *sbsp, *tmpsp;
  164. int *rsp, *psp;
  165. {
  166.     FILE *ifp;
  167.  
  168.     if((ifp = fopen(CONFIG_FILE, "r")) == NULL)
  169.     {
  170.         errmsg(NOCONFIGFILE);
  171.         return(0);
  172.     }
  173.     fscanf(ifp, "%u %u %u %u %u %u %u %u", hsp, strsp, dsp, tsp, sbsp, tmpsp, rsp, psp);
  174.     return(1);
  175. }
  176.  
  177.  
  178. /**************************** more_y_n() **********************************
  179.     Ask for confirmation.
  180.  ************************************************************************/
  181. /* a bit crude ... */
  182. more_y_n()
  183. {
  184.     tty_pr_string("More ?");
  185.     return(read_yes());
  186. }
  187.  
  188. /**************************** read_yes() *********************************
  189.         Return 1 iff user types y
  190. Ignores characters after first non blank.
  191. You could use a dialogue box in a windowing environment.
  192. **************************************************************************/
  193. int read_yes()
  194. {
  195. int c;
  196.  
  197. do
  198.  {
  199.  c = tty_getc();
  200.  }while(isspace(c));
  201.  
  202. while(tty_getc() != '\n');/* read rest of line */
  203.  
  204. if(c == YESLOWER || c == YESUPPER )
  205.   return(1);
  206. else
  207.  return(0);
  208. }
  209.  
  210. #ifdef LINE_EDITOR /* some day ... */
  211. /* this function returns the x and y position of the cursor.
  212.    It's not used but you might want to make use of it to extend
  213.    the input.
  214.  */
  215. /* link with libpc.a */
  216. void gotoxy(X, Y)
  217. short X, Y;
  218. {
  219. ScreenSetCursor(Y,X);
  220. }
  221.  
  222. #endif
  223.  
  224. long  clock()
  225. {
  226. errmsg(" Clock not implemented  on  PC");
  227. /* some recent C User Journal article has a version, I think. */
  228. return(0L);
  229. }
  230.  
  231. /* end of file */
  232.